<template>
  <div class="content routerview viewMargin">
    <header class="mui-bar mui-bar-nav bg-color" v-if="this.$route.meta.isShowHead">
      <!--返回按钮-->
      <span class="iconfont icon-fanhui header_fanhui"  v-show="$store.state.appData.isShowBack" @tap="gotoLast()"></span>
      <!--搜索按钮-->
      <span class="mui-icon mui-icon-search mui-pull-left header_search"  @tap='handleRouteSearch' v-show="$store.state.appData.isShowSousuo"></span>
      <!--标题-->
      <h1 class="mui-title" v-show="this.$route.meta.isShowTitle">{{$store.state.appData.navbarTitle}}</h1>
      <!-- 二次标题 -->
      <h1 class="mui-title" >{{this.$route.meta.secondTitle}}</h1>
      <!--垃圾桶清空选择记录按钮-->
      <span class="mui-icon  icon-icon-- search-right"  v-show="$store.state.appData.isShowClear" @tap='clearallsel()'>
      </span>
    </header>
    <transition :name='$store.state.routerStatus.transition' mode="out-in">
      <router-view></router-view>
    </transition>
    <nav class="mui-bar mui-bar-tab footer" v-if="$store.state.appData.isShowFoot">
      <div class="mui-tab-item" v-for="item in footerMenu" @tap.prevent="goTo(item)" :class="{'mui-active':item.name==$store.state.appData.navbarTitle}">
        <span class="iconfont mui-icon" :class="item.name==$store.state.appData.navbarTitle? item.iconActive: item.icon">
        </span>
        <span class="mui-tab-label">{{item.name}}</span>
      </div>
    </nav>
  </div>
</template>
<script>
import store from './store'
import {getConfigData, configDataGetText} from '@/api/config'
import storage from '@/utils/localstorage'
import mui from 'static/js/mui'
//import mui from 'static/js/mui'
export default {
  components: {},
  name: 'app',
  data(){
    return{
      title:'标题',
      footerMenu:[{
        icon:'icon-shouye',
        iconActive:'icon-shouye2',
        name:'首页',
        router:'/home'
      },
      {
        icon:'icon-xuanche',
        iconActive:'icon-xuanche2',
        name:'选车',
        router:'/filter'
      },
      {
        icon:'icon-dingdan',
        iconActive:'icon-dingdan2',
        name:'订单',
        router:'/orderNavigate'
      },
      {
        icon:'icon-zixun',
        iconActive:'icon-zixun2',
        name:'资讯',
        router:'/carInfo'
      },
      {
        icon:'icon-wode',
        iconActive:'icon-wode2',
        name:'我的',
        router:'/min'
      }
      ]
    }
  },
  created (){
    let that = this;
    //储存全局配置
    getConfigData().then(res=>{
      storage.setLocalstorage('globalConfig',res.data)
      configDataGetText().then(res=>{
        storage.setLocalstorage('configDoc',res.data)
        //当app.vue创建完成以后，自动加载Home.vue模块
        /* if(typeof localStorage.firstIn !== 'undefined'){
          this.$router.push('/guide');
          return;
        }else{ */
          this.goAd()
        //}
      })   
    })
    //获取ios是否安装微信
    if(mui.os.ios){
      document.addEventListener('plusready',function(){
        plus.oauth.getServices(function() {
          let WXApi = plus.ios.import("WXApi");
          let isWXInstalled = WXApi.isWXAppInstalled();
          if(!isWXInstalled){
            that.$store.dispatch('updateWxShow',false)
          }
        })
      },false);
    }

    //监听分享呼起
    document.addEventListener('plusready',function(){
      checkArguments();
    },false);
    // 判断启动方式
    function checkArguments(){
        //console.log("plus.runtime.launcher: "+plus.runtime.launcher);
        var args= plus.runtime.arguments;
        if(args){
            // 处理args参数，如打开新页面等
            alert(args)
        }
    }
    // 处理从后台恢复
    document.addEventListener('newintent',function(){
        //console.log("addEventListener: newintent");
        checkArguments();
    },false);
  	//初始化等待框
  	/* mui.plusReady(function(){
  		plus.nativeUI.showWaiting('初始化')	
  	}  		
  	)
    setTimeout(function(){
  		mui.plusReady(function(){
  			plus.nativeUI.closeWaiting();		
  		}  		
  	)
  		that.$router.push('/home')
    },1000)	 	 */
  },
  methods:{
    goAd() {
      if(!this.$store.state.appData.adHas) {
        this.$router.push({
          path: "/ad"})
      }else{
        //mui.alert('此为测试版，月底将清空数据！','提示')
      }
      return 
    },
    goTo(item){
    	this.$router.push(item.router);
    },
    //清楚选车比价的所有选择
    clearallsel(){
        this.$store.dispatch('clearallchioses')
    },
    handleRouteSearch() {
      this.$router.push({
        path: "/search",
      })
    },
    gotoLast(){
       this.$router.go(-1);//返回上一层
    }
  },
  mounted() {
  }
}
</script>

<style scoped>
@import '~static/common/common.css';
@import '~static/css/muihead.css';

.footer{
  border-top:1px solid #ddd;
  border-bottom: 0px solid #ddd;
} 
.mui-bar {
  z-index:2;
  background-color: #fff;
  -webkit-box-shadow:none;
    box-shadow:none;
    border-bottom:1px solid #ddd;
}

.mui-bar-tab .mui-tab-item {
    height:60px;
}
.mint-tab-item-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 5px
}
.routerview{
	/*position: relative;*/
  z-index: 1;
  overflow: hidden;
  width: 100%;
  height: 100%;
}
.header_fanhui {
  line-height: 43px;
  font-size: 0.9rem;
  width: 43px;
}
.header_search{
  line-height: 43px;
  font-size: 0.9rem;
  padding-top: 0px;
}

.search-right {
  line-height: 30px;
  padding-top: 0px!important;
  color:white;
  float: right;
}

.bg-color {
  box-shadow: 0 0px 0px !important;
}

.fade-enter-active {
    -webkit-transition: all .2s linear;
    transition: all .2s linear;
    opacity: 1
}

.fade-enter, .fade-leave-active {
    opacity: 0;
}
/*过渡动画*/
/*下一页*/
.next-enter-active {
    -webkit-transition: all 0.2s linear;
    transition: all 0.2s linear;
    opacity: 1;
    position: fixed;
    width:100vw;
}

.next-enter, .next-leave-active {
    opacity: 0;
    -webkit-transform: translate3d(50%, 0, 0);
    transform: translate3d(50%, 0, 0);
}

.next-leave-active {
    opacity: 0;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
}
/*上一页*/
.prev-enter-active {
    -webkit-transition: all 0.2s linear;
    transition: all 0.2s linear;
    width:100vw;
}

.prev-enter, .prev-leave-active {
    opacity: 0;
    -webkit-transform: translate3d(-50%, 0, 0);
    transform: translate3d(-50%, 0, 0);
}

.prev-active {
    opacity: 0;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
}

.mui-bar-nav + div{
  margin-top: 44px;
}
/*弃用mui的icon改用自己的iconfont*/
.icon-left-j{
	line-height:30px
}
/* .icon-xuanche{
  font-size:25px;
}
.icon-xuanche2{
  font-size:25px;
} */
</style>
